class Solution {
public:
    int missingNumber(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());

        int lhs = 0, rhs = nums.size();
        int mid = lhs + (rhs - lhs) / 2;

        while (lhs < rhs)
        {
            if (nums[mid] == mid) lhs = mid + 1;
            else rhs = mid;

            mid = lhs + (rhs - lhs) / 2;
        }

        return lhs;
    }
};